package com.leo.book.distributed.chapter04.optimiz;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

public class TestFuture {
	/**
	 * @return
	 */
	private static Object loadData() {
		
		return "loadData";
	}
	
	static class Job<Object> implements Callable<Object> {
		@Override
		public Object call() throws Exception {
			return (Object) loadData();
		}
	}
	
	public static void main(String[] args) throws Exception {
		FutureTask future = new FutureTask(new Job<Object>());
		new Thread(future).start();
		// do something else
		TimeUnit.SECONDS.sleep(3);
		
		Object result = (Object) future.get();
		System.out.println(result);
	}
}